#include <iostream>
#include <vector>
using namespace std;

class Solution {
public:
    /**
     * 代码中的类名、方法名、参数名已经指定，请勿修改，直接返回方法规定的值即可
     *
     * 判断岛屿数量
     * @param grid char字符型vector<vector<>> 
     * @return int整型
     */
    int m, n;
    int dir[4][2] = { {0,1},{1,0},{0,-1},{-1,0} };
    bool vis[205][205]={0};

    void dfs(vector<vector<char> >& grid, int x, int y)
    {
        vis[x][y] = true;
        for (int k = 0; k < 4 ;k++)
        {
            int x1 = x + dir[k][0];
            int y1 = y + dir[k][1];
            if (x1 >= 0 && x1 < m && y1 >= 0 && y1 < n && grid[x1][y1] == '1' && !vis[x1][y1])
            {
                dfs(grid, x1, y1);
            }
        }
    }

    int solve(vector<vector<char> >& grid) {
        // write code here
        m = grid.size(), n = grid[0].size();
        int ret = 0;
        for (int i = 0; i < m; i++)
        {
            for (int j = 0; j < n; j++)
            {
                if (grid[i][j] == '1' && !vis[i][j])
                {
                    ret++;
                    dfs(grid, i, j);
                }
            }
        }
        return ret;
    }
};